package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC3无重复字符的最长子串 {

    public int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<>();
        int slow = 0;
        int i;
        int count = 0;
        for (i = 0; i < s.length(); i++) {
            while(set.contains(s.charAt(i))){
                count = Math.max(count, i -slow);
                set.remove(s.charAt(slow));
                slow++;
            }
            set.add(s.charAt(i));
        }
        return Math.max(count,i-slow);

    }


    @Test
    public void test() {
        // 测试代码
        int i = lengthOfLongestSubstring("pwwkew");
        System.out.println(i);

    }
}
